package org.example.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitConfig {
    public static final String S59_QUEUE_1 ="s59_queue_1";
    public static final String S59_QUEUE_2 ="s59_queue_2";

    public static final String S59_DIRECT_EXCHANGE ="s59_direct_exchange";//精确

//    public static final String S59_TOPIC_EXCHANGE ="s59_topic_exchange";//模糊
//
    public static final String S59_FANOUT_EXCHANGE ="s59_fanout_exchange";//不论
    @Bean
    public Queue queue1(){
        return new Queue(S59_QUEUE_1,true);
    }

    @Bean
    public Queue queue2(){
        return new Queue(S59_QUEUE_2,true);
    }

    //跟路由器无关
    @Bean
    FanoutExchange fanoutExchange(){
        return new FanoutExchange(S59_FANOUT_EXCHANGE);
    }

    @Bean
    public Binding binding1(){
        return BindingBuilder.bind(queue1()).to(fanoutExchange());
    }
    @Bean
    public Binding binding2(){
        return BindingBuilder.bind(queue2()).to(fanoutExchange());
    }


//模糊匹配
//    @Bean
//    public TopicExchange topicExchange(){
//        return new TopicExchange(S59_TOPIC_EXCHANGE);
//    }

//    @Bean
//    public Binding binding1(){
//        return BindingBuilder.bind(queue1()).to(topicExchange()).with("#.red.#");
//    }
//    @Bean
//    public Binding binding2(){
//        return BindingBuilder.bind(queue2()).to(topicExchange()).with("#.green.#");
//    }


//精确匹配路由器
//    @Bean
//    public DirectExchange directExchange(){
//        return new DirectExchange(S59_DIRECT_EXCHANGE);
//    }//交换机
//
//    @Bean
//    public Binding binding1(){
//        return BindingBuilder.bind(queue1()).to(directExchange()).with("red");
//    }//交换机绑定配置，队列1精确绑定条件
//
//    @Bean
//    public Binding binding2(){
//        return BindingBuilder.bind(queue2()).to(directExchange()).with("green");
//    }//绑定队列2
}
